package cn.tedu.sp04.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;

@RestController
@Slf4j
public class OrderController {

     @Resource
    private OrderService service;

     @GetMapping("/{orderId}")
     public JsonResult<Order> getOrder(@PathVariable String orderId){
         Order order=service.getOrders(orderId);
         return JsonResult.ok().data(order);
     }
@GetMapping("/add")
public JsonResult<?> addOrder(){
         Order order=new Order();
         order.setId("123");
         order.setUser(new User(8,null,null));
         order.setItems(Arrays.asList(new Item[]{
             new Item(1,"商品1",1),
             new Item(2,"商品2",10),
             new Item(3,"商品3",5)

     }));
    //service.addOrder(order);
     return JsonResult.ok().msg("添加商品成功").data(order);

}

    //象浏览器放回一个空数据，不会报错
    @GetMapping("/favicon.ico")
    public void ico(){


    }


}
